package org.jeecg.attachment.dto.util;

import org.jeecg.attachment.entity.SysAttachment;
import org.jeecg.common.constant.enums.BoolInt;
import org.jeecg.common.util.FileUtil;

import java.util.Date;

/**
 *
 * @author: qiang.zhou
 * @date: 2024/9/6 14:06
 **/
public class AttachmentUtil {

    public static SysAttachment buildSysAttachment(long fileSize, String userId, String md5, String fileName, String fileNo, SysAttachment old) {
        SysAttachment attachment = new SysAttachment();
        attachment.setFileName(fileName);
        attachment.setFileUrl(old.getFileUrl());
        attachment.setFileType(FileUtil.getFileType(fileName, ""));
        attachment.setFileSize(String.valueOf(fileSize));
        attachment.setDownloadNum(0);
        attachment.setMd5(md5);
        attachment.setUploadFull(old.getUploadFull());
        attachment.setGroupNumber(fileNo);
        attachment.setCreateBy(userId);
        attachment.setCreateTime(new Date());
        attachment.setUpdateBy(userId);
        attachment.setUpdateTime(new Date());
        return attachment;
    }

    public static SysAttachment buildSysAttachment(String userId, String fileDirectory, String fileName, String md5, String fileNo, long fileSize) {
        SysAttachment attachment = new SysAttachment();
        attachment.setFileName(fileName);
        attachment.setFileUrl(fileDirectory);
        attachment.setFileType(FileUtil.getFileType(fileName, ""));
        attachment.setFileSize(String.valueOf(fileSize));
        attachment.setMd5(md5);
        attachment.setUploadFull(BoolInt.FALSE.getCode());
        attachment.setGroupNumber(fileNo);
        attachment.setCreateBy(userId);
        attachment.setCreateTime(new Date());
        attachment.setUpdateBy(userId);
        attachment.setUpdateTime(new Date());
        return attachment;
    }


}
